package gui.panels;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import mysql.LocationQueries;
import mysql.MoviesQueries;
import objects.Location;
import objects.Movie;

public class AddLocation extends JFrame implements ActionListener {

	public Location loccurrentEntry;
	public LocationQueries locQueries;
	public List<Location> locResults;
	public int locnumberOfEntries = 0;
	public int locCurrentEntryIndex = 0;

	private JLabel addressLabel;
	public JTextField addressText;
	private JLabel stateLabel;
	public JTextField stateText;
	
	public JButton add;
	public JButton cancel;
	public JPanel displayPanel;
	public int nextEntry;

	public AddLocation() {
		setData();
		addressLabel = new JLabel("Address:");
		addressText = new JTextField(20);
		stateLabel = new JLabel("State:");
		stateText = new JTextField(20);
		displayPanel = new JPanel();
		add = new JButton("Add new location");
		cancel = new JButton("Cancel");

		displayPanel.setLayout(new GridLayout(3, 2, 4, 4));
		displayPanel.add(addressLabel);
		displayPanel.add(addressText);
		displayPanel.add(stateLabel);
		displayPanel.add(stateText);
		displayPanel.add(add);
		displayPanel.add(cancel);

		add.addActionListener(this);
		cancel.addActionListener(this);

		add(displayPanel, BorderLayout.CENTER);
		pack();
		setVisible(true);
	}

	private void setData() {
		locQueries = new LocationQueries();
		locResults = locQueries.getAllLocations();
		nextEntry = locResults.size()+101;
		System.out.println(locResults.size());
		System.out.println(nextEntry);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getSource() == this.add) {
			locQueries.addLocation(nextEntry, addressText.getText(), stateText.getText());
			super.dispose();
		}
		if (arg0.getSource() == this.cancel) {
			super.dispose();
		}
	}

}
